package com.web.graduationpro.common;

import javax.servlet.http.HttpServletRequest;

import com.web.graduationpro.dao.service.ArticleService;
import com.web.graduationpro.dao.service.GoodsService;
import com.web.graduationpro.dao.service.InstrumentSchoolService;
import com.web.graduationpro.dao.service.TeacherService;

/**
 * 前端公共数据处理类
 */
public class CommonDataClass {
	
	private InstrumentSchoolService instrumentSchoolServiceImpl;

	private TeacherService teacherServiceImpl;

	private GoodsService goodsServiceImpl;

	private ArticleService articleServiceImpl;
	
	private HttpServletRequest request;
	
	public CommonDataClass(
			InstrumentSchoolService instrumentSchoolServiceImpl,
			TeacherService teacherServiceImpl,
			GoodsService goodsServiceImpl,
			ArticleService articleServiceImpl,
			HttpServletRequest request) {
        this.instrumentSchoolServiceImpl = instrumentSchoolServiceImpl;
        this.teacherServiceImpl = teacherServiceImpl;
        this.goodsServiceImpl = goodsServiceImpl;
        this.articleServiceImpl = articleServiceImpl;
        this.request = request;
        
        recommendTeacher();
        recommendInstrument();
        recommendBooks();
        recommendInstrumentSchool();
        newCourses();
        tradeNewses();
	}
	
	/*************************************************************/
	//推荐老师
	public void recommendTeacher(){
		String queryHql = "  FROM Teacher tc WHERE tc.id!=0";
		request.setAttribute("recommendTeacher",teacherServiceImpl.findByPage(queryHql, 0, 5));
	}
	
	//推荐乐器
	public void recommendInstrument(){
		String queryHql = "  FROM Goods gd WHERE gd.id!=0 and gd.goodsType.id=1";
		request.setAttribute("recommendInstrument",goodsServiceImpl.findByPage(queryHql, 0, 5));
	}
	
	//推荐书籍
	public void recommendBooks(){
		String queryHql = "  FROM Goods gd WHERE gd.id!=0 and gd.goodsType.id=2";
		request.setAttribute("recommendBooks",goodsServiceImpl.findByPage(queryHql, 0, 5));
	}
	/*************************************************************/
	
	/*************************************************************/
	//推荐学校
	public void recommendInstrumentSchool(){
		String queryHql = "  FROM InstrumentSchool ischool WHERE ischool.id!=0 AND ischool.isRecommend=1";
		request.setAttribute("recommendInstrumentSchools",instrumentSchoolServiceImpl.findByPage(queryHql, 0, 5));
	}
	
	//最新开课
	public void newCourses(){
		String queryHql = "  FROM Article ac WHERE ac.id!=0 AND ac.articleType.id=1";
		request.setAttribute("newCourses",articleServiceImpl.findByPage(queryHql, 0, 5));
	}
	
	//行业新闻
	public void tradeNewses(){
		String queryHql = "  FROM Article ac WHERE ac.id!=0 AND ac.articleType.id=2";
		request.setAttribute("tradeNewses",articleServiceImpl.findByPage(queryHql, 0, 5));
	}
	/*************************************************************/
}
